//
//  YLAdLineFooterViewModel.m
//  YLFinanceService
//
//  Created by she1323 on 2017/10/18.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLAdLineFooterViewModel.h"
#import "WHNetworkTool.h"
#import "YLAccountTool.h"
#import "YLAdLineFooterModel.h"
#import <YYModel.h>
#import "WHProgressHUD.h"
@implementation YLAdLineFooterViewModel

- (instancetype)init
{
    if (self = [super init]) {
        [self setUp];
    }
    return self;
}

- (void)setUp
{
    _aDCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
       
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            

            NSString *url = [NSString stringWithFormat:@"%@AppCommon/PGetLoopNitoce", YLURL];
            
            [[WHNetworkTool shareInstance] sendPostWithUrl:url header:[YLAccountTool header] params:nil success:^(id responseObject) {
                
                if ([responseObject[@"httpCode"] integerValue] == 200) {
                    YLAdLineFooterModel *model = [YLAdLineFooterModel yy_modelWithDictionary:responseObject[@"httpResult"]];
                    [subscriber sendNext:model.item];
                    
                } else {
                    [WHProgressHUD showError:responseObject[@"message"]];
                }
                                
                
                [subscriber sendCompleted];
            } fail:^(NSError *error) {
                [subscriber sendCompleted];
            }];
            
            
            return nil;
        }];
        
    }];
}

- (void)dealloc
{
    [WHProgressHUD dismiss];
    [[WHNetworkTool shareInstance] cancel];
}

@end
